#region Using References

using System.Diagnostics.Contracts;
using Beaker.OpenCube.Mapping;

#endregion

namespace Beaker.OpenCube.Game
{
	public sealed class ChunkSection
	{
		public ChunkSection()
		{
			Contract.Ensures( _blockIds != null );
			Contract.Ensures( _blockIdHigh != null );
			Contract.Ensures( _blockData != null );
			Contract.Ensures( _blockLight != null );
			Contract.Ensures( _skyLight != null );
		}

		/// <summary>
		/// Gets or sets the Y index (not coordinate) of this section. 
		/// </summary>
		/// <remarks>
		/// Range 0 to 15 (bottom to top), with no duplicates but some sections may be missing if empty.
		/// </remarks>
		public byte Y { get; set; }

		private readonly byte[] _blockIds = new byte[4096];

		/// <summary>
		/// Gets the block id's for this chunk-section
		/// </summary>
		[Pure]
		public byte[] Blocks
		{
			get
			{
				Contract.Ensures( Contract.Result<byte[]>() != null );
				return _blockIds;
			}
		}

		private readonly byte[] _blockIdHigh = new byte[2048];

		/// <summary>
		/// Gets the additional chunkid information for this chunk-section
		/// </summary>
		[Pure]
		[Mapping( IsOptional = true )]
		public byte[] Add
		{
			get
			{
				Contract.Ensures( Contract.Result<byte[]>() != null );
				return _blockIdHigh;
			}
		}


		private readonly byte[] _blockData = new byte[2048];

		/// <summary>
		/// Gets the block data for this chunk-section
		/// </summary>
		[Pure]
		public byte[] Data
		{
			get
			{
				Contract.Ensures( Contract.Result<byte[]>() != null );
				return _blockData;
			}
		}

		private readonly byte[] _blockLight = new byte[2048];

		/// <summary>
		/// Gets the blocklight information for this chunk-section
		/// </summary>
		[Pure]
		public byte[] BlockLight
		{
			get
			{
				Contract.Ensures( Contract.Result<byte[]>() != null );
				return _blockLight;
			}
		}

		private readonly byte[] _skyLight = new byte[2048];

		/// <summary>
		/// Gets the skylight information for this chunk-section
		/// </summary>
		[Pure]
		public byte[] SkyLight
		{
			get
			{
				Contract.Ensures( Contract.Result<byte[]>() != null );
				return _skyLight;
			}
		}

	}
}